<?php

class InventoryController extends Controller
{
	public function filters()
    {
        return array(
            'accessControl',
        );
    }
    
	public function accessRules()
	{
		return array(
			array('deny',
				'users' => array('?')
			)
		);
	}
	
	public function actionIndex()
	{
		$this->render('index');
	}
	
	public function actionItems()
	{
        $criteria = new CDbCriteria();
	    $count = Item::model()->count($criteria);
	    $pages = new CPagination($count);
	
	    // results per page
	    $pages->pageSize = 10;
	    $pages->applyLimit($criteria);
	    $itemList = Item::model()->findAll($criteria);
	    
	    $quantity_decimals = Yii::app()->user->getState('quantity_decimals');

		$this->render('items',array('itemList'=>$itemList,'pages'=>$pages,'quantityDecimals'=>$quantity_decimals));
	}
	
	public function actionCategories()
	{

		$criteria = new CDbCriteria();
	    $count = ItemCategory::model()->count($criteria);
	    $pages = new CPagination($count);
	
	    // results per page
	    $pages->pageSize = 10;
	    $pages->applyLimit($criteria);
	    $categoryList = ItemCategory::model()->findAll($criteria);
		
		$this->render('categories',array('listItems'=>$categoryList, 'pages'=>$pages));
	}
	
	public function actionLocations()
	{
		$criteria = new CDbCriteria();
	    $count = InventoryLocation::model()->count($criteria);
	    $pages = new CPagination($count);
	
	    // results per page
	    $pages->pageSize = 10;
	    $pages->applyLimit($criteria);
	    $locationList = InventoryLocation::model()->findAll($criteria);
	    
		$this->render('locations', array('locationList'=>$locationList, 'pages'=>$pages));
	}


}